//
//  fTtJkxJLCFListRecordViewControllerlJnAft.m
//  Jlcf_ios
//
//  Created by zl on 2018/10/18.
//  Copyright © 2018年 ski. All rights reserved.
//

#import "fTtJkxJLCFListRecordViewControllerlJnAft.h"
#import "JLCFTableViewCell.h"
#import "XvmSEfJLCFListRequestdkZIyb.h"
#import "MdckAUJLCFListRecodModelSbWSuQ.h"
#import "VmdbCAJLCFListRecordTableViewCellcbXRww.h"

@interface fTtJkxJLCFListRecordViewControllerlJnAft ()
{
    NSInteger _pageNumber;
}
@property (nonatomic, strong) NSMutableArray *qxoleRrecordArrwnbbYO;

@end

@implementation fTtJkxJLCFListRecordViewControllerlJnAft


- (NSMutableArray *)qxoleRrecordArrwnbbYO
{
    if (!_qxoleRrecordArrwnbbYO) {
        _qxoleRrecordArrwnbbYO = [NSMutableArray array];
    }
    return _qxoleRrecordArrwnbbYO;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    
    self.navigationBar.title = @"出借记录";
    
    self.view.frame = CGRectMake(0, 0, FULL_WIDTH, FULL_HEIGHT);
    self.tableView.frame = CGRectMake(0, NAVBAR_HEIGHT, FULL_WIDTH, self.view.height - NAVBAR_HEIGHT);
    self.tableView.backgroundColor = QTZ_Gray237;
    
    [self loadData];
    // Do any additional setup after loading the view.
}


- (void)loadData
{
    [self.qxoleRrecordArrwnbbYO removeAllObjects];
    _pageNumber = 1;
    
    [XvmSEfJLCFListRequestdkZIyb getBorrowRecord:@{@"id":self.proId,@"page" : @(_pageNumber) } loadingInView:self.tableView success:^(MdckAUJLCFListRecodModelSbWSuQ *list) {
        
        [self hideNoMoreDataNotice];
        self.tableView.mj_footer.hidden = NO;
        [self.qxoleRrecordArrwnbbYO addObjectsFromSafeArray:list.data];
        [self.tableView reloadData];
        [self endRefresh];
        
    } failure:^(NSString *error) {
        [self showNotice:error];
        [self endRefresh];
    }];
    
}

- (void)loadMoreData
{
    _pageNumber ++;
    
    [XvmSEfJLCFListRequestdkZIyb getBorrowRecord:@{@"id":self.proId,@"page" : @(_pageNumber) } loadingInView:self.tableView success:^(MdckAUJLCFListRecodModelSbWSuQ *list) {
        
        if (list > 0) {
            
            [self.qxoleRrecordArrwnbbYO addObjectsFromSafeArray:list.data];
        } else {
            self.tableView.mj_footer.hidden = YES;
            [self showNoMoreDataNotice:@"没有更多了"];
        }
        [self.tableView reloadData];
        [self endLoadMore];
        
    } failure:^(NSString *error) {
        [self showNotice:error];
        [self endLoadMore];
    }];
    
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 2;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return section == 0? 1 : self.qxoleRrecordArrwnbbYO.count ;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 45;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    VmdbCAJLCFListRecordTableViewCellcbXRww *cell = [VmdbCAJLCFListRecordTableViewCellcbXRww dequeueReusableCellForTableView:tableView];
    if (indexPath.section == 1) {
        if (_qxoleRrecordArrwnbbYO) {
            cell.data = [_qxoleRrecordArrwnbbYO safeObjectAtIndex:indexPath.row];
                
        }
    }
    [cell reloadDataWithIfENDCell:indexPath.row == _qxoleRrecordArrwnbbYO.count-1 && indexPath.section!=0];
    return cell;
    
}

- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    if ([cell respondsToSelector:@selector(tintColor)]) {
        
        if (tableView == self.tableView) {
            
            CGFloat cornerRadius = 0.f;
            
            cell.backgroundColor = UIColor.clearColor;
            
            CAShapeLayer *layer = [[CAShapeLayer alloc] init];
            
            CGMutablePathRef pathRef = CGPathCreateMutable();
            
            CGRect bounds = CGRectInset(cell.bounds, 0, 0);
            
            if (indexPath.row == 0 && indexPath.row == [tableView numberOfRowsInSection:indexPath.section]-1) {
                
                CGPathAddRoundedRect(pathRef, nil, bounds, cornerRadius, cornerRadius);
                
            } else if (indexPath.row == 0) {
                
                CGPathMoveToPoint(pathRef, nil, CGRectGetMinX(bounds), CGRectGetMaxY(bounds));
                
                CGPathAddArcToPoint(pathRef, nil, CGRectGetMinX(bounds), CGRectGetMinY(bounds), CGRectGetMidX(bounds), CGRectGetMinY(bounds), cornerRadius);
                
                CGPathAddArcToPoint(pathRef, nil, CGRectGetMaxX(bounds), CGRectGetMinY(bounds), CGRectGetMaxX(bounds), CGRectGetMidY(bounds), cornerRadius);
                
                CGPathAddLineToPoint(pathRef, nil, CGRectGetMaxX(bounds), CGRectGetMaxY(bounds));
                
            } else if (indexPath.row == [tableView numberOfRowsInSection:indexPath.section]-1) {
                
                CGPathMoveToPoint(pathRef, nil, CGRectGetMinX(bounds), CGRectGetMinY(bounds));
                
                CGPathAddArcToPoint(pathRef, nil, CGRectGetMinX(bounds), CGRectGetMaxY(bounds), CGRectGetMidX(bounds), CGRectGetMaxY(bounds), cornerRadius);
                
                CGPathAddArcToPoint(pathRef, nil, CGRectGetMaxX(bounds), CGRectGetMaxY(bounds), CGRectGetMaxX(bounds), CGRectGetMidY(bounds), cornerRadius);
                
                CGPathAddLineToPoint(pathRef, nil, CGRectGetMaxX(bounds), CGRectGetMinY(bounds));
                
            } else {
                
                CGPathAddRect(pathRef, nil, bounds);
                
            }
            
            layer.path = pathRef;
            
            CFRelease(pathRef);
            
            layer.fillColor = [UIColor colorWithWhite:1.f alpha:1.f].CGColor;
            
            
            UIView *testView = [[UIView alloc] initWithFrame:bounds];
            
            [testView.layer insertSublayer:layer atIndex:0];
            
            testView.backgroundColor = UIColor.clearColor;
            
            cell.backgroundView = testView;
            
        }
        
    }
    
}




- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view PzfRvYcontrollerLrnibE using [segue destinationViewController].
    // Pass the selected object to the new view PzfRvYcontrollerLrnibE.
}
*/

@end
